<template>
  <div>
    <TopFilter :list="topFilterList" :collapse="false" @filterChange="changeHandle"
               @onCollapse="collapseHandle"></TopFilter>
    <FilterTable
      height="400"
      :selectionType="selectionType"
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="getfetchParams"
      datakey="records"
      :onColumnsChange="columns => (this.columns = columns)"
      :onSyncTableData="tableChangeFun"
      :onRowSelectChange="selectChange"
    >
    </FilterTable>
    <div class="dialogBottmView">
      <el-button size="small" type="primary" class="btnStyle" @click="submitBtn">确定
      </el-button>
      <el-button size="small" type="primary" class="btnStyle" @click="closeDialog">取消
      </el-button>
    </div>
  </div>
</template>

<script>
import {dictionary} from '@/utils/dictMixin';
import {getCar} from '@/api/partsmanage/purchaseManage/purchaseSubmit';

export default {
  name: 'Vehicle',
  components: {},
  mixins: [dictionary],
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createTopFilterList(),
      visible: false,
      fetchApi: getCar,
      fetchParams: {
        xhrAbort:true
      },
      columns: this.createTableColumns(),
      selectArr: []
    };
  },
  props: {
    selectionType: {},
    params: {
      type: Object,
      default() {
        return {}
      }
    }
  },//'single':'multiple' 单选多选
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  computed: {
    getfetchParams() {
      return Object.assign({}, this.params, this.fetchParams);
    }
  },
  methods: {
    tableChangeFun(val) {
    },
    selectChange(val) {
      this.selectArr = val
      console.log(val)
    },
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          sorter: true,
        },
        {
          title: '动力形式',
          dataIndex: 'powerType',
          sorter: true,
          dictItems: this.createDictList(6008),
        },
        {
          title: '车主编号',
          dataIndex: 'ownerNo',
          sorter: true,
        },
        {
          title: '客户编号',
          dataIndex: 'customerNo',
          sorter: true,
        },
        {
          title: '车牌号',
          dataIndex: 'license',
          sorter: true,
        },
        {
          title: '发动机号',
          dataIndex: 'engineNo',
          sorter: true,
        },
        {
          title: '车型年款',
          dataIndex: 'modelYear',
          sorter: true,
        },
      ]
    },
    createTopFilterList() {
      return [
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vinOne',
          placeholder: '车辆唯一识别代码...',
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'blur'
            }]
        }
      ];
    },

    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },

    changeHandle(val) {
      delete this.fetchParams.xhrAbort
      this.fetchParams = Object.assign({}, val);
    },


    closeHandler(val, type) {
      this.visible = val;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = {...this.fetchParams};
      }
    },
    closeDialog() {
      this.$emit('closeDialog')
    },
    submitBtn() {
      if (this.selectArr.length == 0) {
        this.$notify.warning({title: '提示信息', message: '请您选择车辆'});
        return
      }
      this.$emit('selectArr', this.selectArr)
    }
  }
};
</script>

<style lang="less" scoped>
.dialogBottmView {
  text-align: center;
}
</style>
